package com.huatec.controller;

import com.huatec.service.StudentService;
import com.huatec.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService studentService;

//    根据StuClassId查询学生信息
    @RequestMapping(value="/loadByStuClassId/{stuClassId}",method= RequestMethod.GET)
    @ResponseBody
    public Result loadByStuClassId(@PathVariable("stuClassId") int stuClassId){

        Result result=studentService.loadStudentList(stuClassId);
        return result;
    }
//    查询全校学生列表
    @RequestMapping(value="/loadAll",method=RequestMethod.GET)
    @ResponseBody
    public Result loadByStuClassId(){
        Result result=studentService.loadStudentList(1,10);
        return result;
    }

    //新增学生信息
    @RequestMapping(value = "/addStudent",method=RequestMethod.POST)
    @ResponseBody
    public Result addStudent(String studentNum, String studentName, String username,String password,
                             int studentSex, String mobilePhone, String email, int classId){
        Result result=studentService.addStudent(studentNum, studentName, username,password, studentSex, mobilePhone, email, classId);
        return result;
    }
//删除学生
    @RequestMapping(value="/deleteStudentById/{studentId}",method=RequestMethod.DELETE)
    @ResponseBody
    public Result deleteStudentById(@PathVariable("studentId") int studentId){
        Result result=studentService.deleteStudentById(studentId);
        return result;
    }
//修改学生
//    @RequestMapping(value="/updateStudent/{studentId}/{password}",method=RequestMethod.PUT)
//    @ResponseBody
//    public Result updateStudent(@PathVariable("studentId") int studentId, String studentNum,
//                             String studentName, String username,@PathVariable("password") String password,int studentSex, String mobilePhone, String email) {
//        Result result = studentService.updateStudent(studentId, studentNum, studentName,
//                username,password, studentSex, mobilePhone, email);
//        return result;
//    }
    @RequestMapping(value="/updateStudent/{studentId}/{password}",method=RequestMethod.PUT)
    @ResponseBody
    public Result updateStudent(@PathVariable("studentId") int studentId, String studentNum,
                                String studentName, String username,@PathVariable("password") String password,String mobilePhone, String email) {
        Result result = studentService.updateStudent(studentId, studentNum, studentName,
                username,password, mobilePhone, email);
        return result;
    }
//    通过id查询学生
    @RequestMapping(value="/findStudentById/{studentId}",method=RequestMethod.GET)
    @ResponseBody
    public Result findStudentById(@PathVariable("studentId") int studentId){

        Result result=studentService.loadStudentById(studentId);
        return result;
    }

    //根据学生学号、真实姓名关键字去搜索
    @RequestMapping(value="/loadByKeywords",method=RequestMethod.POST)
    @ResponseBody
    public Result loadByKeywords(String keywords){
        Result result=studentService.loadStudentList(keywords);
        return result;
    }
//通过 studentNum查询学生，提供给饭卡管理系统用
    @RequestMapping(value="/findStudentByNum/{studentNum}",method=RequestMethod.GET)
    @ResponseBody
    public Result findStudentByNum(@PathVariable(name="studentNum") String studentNum){
        Result result=studentService.loadStudentByNum(studentNum);
        return result;
    }

}
